//
//  LZRestaurantHeaderViewControl.m
//  laziz_Consumer
//
//  Created by xbn_iMac on 2016/11/21.
//  Copyright © 2016年 XBN. All rights reserved.
//

#import "LZRestaurantHeaderViewControl.h"
#import "UIView+Rotation.h"
#import "Masonry.h"

@interface LZRestaurantHeaderViewControl ()

@property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UIView *line;

@end

@implementation LZRestaurantHeaderViewControl

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self configSubviews];
        self.selected = NO;
        self.line.hidden = !self.selected;
        [self addTarget:self action:@selector(clickAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}

- (void)configSubviews {
    self.label = [[UILabel alloc] init];
    // 评价餐厅
    self.label.text = LZLocalizedString(@"review_about_restaurant", nil);
    self.label.textColor = UIColorFromRGB(0x333333, 1);
    self.label.font = [UIFont systemFontOfSize:15];
    [self addSubview:self.label];
    
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(10);
        make.centerY.equalTo(self);
    }];
    
    self.imageView = [[UIImageView alloc] init];
    self.imageView.image = [UIImage imageNamed:@"comment_av_view_down"];
    [self addSubview:self.imageView];
    
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self).offset(-10);
        make.centerY.equalTo(self);
        make.width.equalTo(12);
        make.height.equalTo(6);
    }];
    
    self.line = [[UIView alloc] init];
    self.line.backgroundColor = UIColorFromRGB(0xeeeeee, 1);
    [self addSubview:self.line];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self).offset(10);
        make.trailing.equalTo(self).offset(-10);
        make.height.equalTo(0.5);
        make.bottom.equalTo(self).offset(-0.5);
    }];
    
}

- (void)clickAction:(UIControl*)sender {
    sender.selected = !sender.selected;
    self.line.hidden = !sender.selected;
    self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, M_PI);
    if (self.ClickBolck) {
        self.ClickBolck(sender.selected);
    }
}


@end
